package com.efast.dmom.mgmt.service.mes.qm.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.bean.mes.qm.IQCBean;
import com.efast.dmom.mgmt.dao.mes.qm.IQCQualityDao;
import com.efast.dmom.mgmt.service.mes.qm.IQCQualityService;

@Service
public class IQCQualityServiceImpl implements IQCQualityService{
	
	@Autowired
	private IQCQualityDao iqcQualityDao;

	@Override
	public ResultBean verifyRepetition(IQCBean iqcBean) {
		
		ResultBean resultBean =  new ResultBean(true,"");
		DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
		String format = format1.format(iqcBean.getOccurDate());
		iqcBean.setOoc(format);
		int qty = iqcQualityDao.verifyRepetition(iqcBean);
		if (iqcBean.getFlag().equals("edit")) {
			if (qty >= 1 ) {
				resultBean.setSuccess(false);
				resultBean.setMessage("该条数据已重复！");
				return resultBean;
			}
		} else {
			if (qty > 0 ) {
				resultBean.setSuccess(false);
				resultBean.setMessage("该条数据已重复！");
				return resultBean;
			}
		}
			
		return resultBean;
	}

}
